<template>
	<div class="circle_create">
		<!-- <so-header :seller="headerTitle"></so-header> -->
    <setHeader :title="headerTitle"></setHeader>
    <div class="pagecontent">
        <!-- <div class="write_input_box main-company-input" style="margin-top: 0.2rem;">
            <label for="">圈子名称：</label>
            <input type="text" placeholder="请输入圈子名称" v-model="circlename">
        </div> -->
				
        <!-- 请输入圈子名称 -->
        <CircleAutocomplete :placeholder="placeholder" @circledate='companyClick'></CircleAutocomplete>
        <div class="btn_big_red" @click="NextStep" style="margin-top: 0.9rem;">
            <button>下一步</button>
        </div>
    </div>

		<!-- <mt-field label="圈子名称:" placeholder="请输入圈子名称"  v-model="circlename"></mt-field>
		<mt-button type="default" class="el-long-button el-long-create-button"  @click="NextStep">下一步</mt-button> -->
		<!-- <so-footer :user="fill"></so-footer> -->
	</div>
</template>
<script>
import setHeader from '../public/setHeader.vue';
import CircleAutocomplete from '@/components/circleAutocomplete';
import { MessageBox } from 'mint-ui';


export default {
	data() {
      return {
        circlename: '',
        userInfo:'',
				headerTitle:'输入圈子名称',
				placeholder: '请输入圈子名称'
      };
    },
    components: {
		setHeader,
		CircleAutocomplete
	},
    created() {
      let that = this;
      that.userInfo = window.localStorage.getItem('userInfo');
      that.userInfo = JSON.parse(that.userInfo);
    },
    mounted() {
    	// let that = this;
    	// var a = Promise.resolve(this.getUserInfo())
			// a.then(
			// 	function (result) { 
			// 	that.userInfo = result;
			// })
      //console.log(this.userInfo);
    },
    methods:{
			companyClick(circle_name) {
				this.circlename = circle_name;
			},
    	NextStep:function(){
    		
    		let that = this;
    		let uid = that.userInfo.uid;
    		let circlename = this.circlename;
    		if(circlename == '' || circlename == undefined){
    			MessageBox('温馨提示', '请输入圈子名称');
    		}else{
    			this.$post(
                that.$path+'/api.php/company/getUserAllCompanyList',{userId:uid})
                .then((res) => {
	               let count = res.count;
		            if(count < 1){
		                MessageBox.alert('您需要先绑定企业').then(action => {
		                	this.$router.push({path: '/companyCreate'}); 
		                });
		            }else{
		                this.$post(
		                  that.$path+'/api.php/Circle/checkCircleName',{c_name:circlename, uid})
		                .then((res) => {
		                  if(res.code == 200){
		                  	this.$router.push({path: '/incircle', query: {paicheNo: res.data.cid}}); 
		     //              	MessageBox.confirm('此圈子名称已被创建 请换一个名称 或加入此圈').then(action => {
		     //                  this.$router.push({path: '/userCenter/circleindex', query: {paicheNo: res.data.cid}}); 
							// });
											}
											else if(res.code == 301) {
													MessageBox('提示', '您已创建过相同的圈子');
											}
											else if(res.code == 302) {
													MessageBox('提示', '圈子已存在且您已加入该圈子');
											}
		                  else if(res.code == 202){
		                  	//新创建圈子
		                  	this.$router.push({path: '/createNewCircle', query: {circlename: circlename}}); 

						  }
						  else{
							MessageBox('提示', response.msg)
							return false;
						}
		                })
		            }
          		})		
    		}	
    	},
    }
}

</script>

<style >

/* 请输入圈子名称 */
.main-company-input {
	margin-bottom: 1.4rem;
}
.main-company-input input {
	width: 76% !important;
}
 /* 头部颜色 */
 .circle_create .header_array_text_white {
   background-color: #fff;
   color: #000;
 }
 .circle_create .header_array_text_white .title_white {
   color: #000;
 }
</style>